home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13788 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.1 KB  |  74 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!marnold
  3. From: marnold@netcom.com (Matt Arnold)
  4. Subject: Re: STL destroy() and warnings
  5. Message-ID: <marnoldDox3tn.C6u@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. References: <J.Hamer-2703960916160001@john-ha.cs.auckland.ac.nz>
  8. Date: Wed, 27 Mar 1996 08:34:35 GMT
  9. Sender: marnold@netcom18.netcom.com
  10.  
  11. J.Hamer@cs.auckland.ac.nz (John Hamer) writes:
  12.  
  13. >These questions relate to the October 31, 1995 release of the
  14. >Hewlett-Packard implementation of STL, running under Borland C++ 4.5.
  15.  
  16. >1. This STL implementation does not appear to be able to cope directly
  17. >with a container of pointers.  The template for destroy() in defalloc.h
  18. >attempts to call pointer->~T() where T is a pointer to a pointer type, and
  19. >a compiler error results.  What are the recommended work-arounds?
  20.  
  21. You must write your own destroy() function for your specific types.  Most
  22. C++ compilers will not compile an explicit destructor call for a pointer
  23. type.
  24.  
  25. For example, if you have some container of Foo pointers, you need to 
  26. provide this somwhere...
  27.  
  28.    void destroy(Foo**) { }
  29.  
  30. This *is* the intended work-around in the current version of STL for 
  31. compilers that cannot correctly instantiate the template...
  32.  
  33.    template <class T>
  34.    void destroy(T* pointer) { pointer->~T(); }
  35.  
  36. ...for any type T (which doesn't really do anything if T is a pointer
  37. anyway).
  38.  
  39. STL uses this work-around itself.  See "defalloc.h" where it defines a
  40. bunch of "do-nothing" destroy() functions for as many pointers to 
  41. integral types (such as ints, chars and floats) that the authors thought 
  42. would be useful.  
  43.  
  44. I believe Borland C++ 5.0 is one of the compiler's out now that will
  45. correctly instantiate the destroy() template for any type T.  With 4.5,
  46. you will need the manual work-around.
  47.  
  48. >2. I get a large number of compiler warnings about ``Conversion will lose
  49. >significant digits'' when compiling with the large memory model.  This
  50. >looks to be more of a nuisance than a problem; are there any patches
  51. >available to make the compiler shut up?
  52.  
  53. Turn off that warning (see Options|Project|Messages|Portability).  Or, go 
  54. through the STL code and insert the appropriate casts to show the compiler 
  55. that the code really knows what its doing.
  56.  
  57. In the world of segmented addresses, you get this warning when you try to
  58. add more than a 16-bit quantity to a pointer (or index into an array with 
  59. more than a 16-bit quantity).  I believe the STL code does quite a bit of
  60. this.
  61.  
  62. If you are just getting into STL, I highly recommend the book "The C++
  63. Programmer's Guide to The Standard Template Library" from IDG books.  It
  64. is very complete.
  65.  
  66. Regards,
  67. -------------------------------------------------------------------------
  68. Matt Arnold                       |        | ||| | |||| |  | | || ||
  69. marnold@netcom.com                |        | ||| | |||| |  | | || ||
  70. Boston, MA                        |      0 | ||| | |||| |  | | || ||
  71. 617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
  72. C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
  73. -------------------------------------------------------------------------
  74.